<template>
    <h2>房价列表</h2>
    <input type="button" value="导出" @click="daochuwmws">
    <input type="button" value="录入房号" @click="luruwjms">
    <table>
        <tr>
            <td>房价名称</td>
            <td>房间价格</td>
            <td>创建时间</td>
            <td>房间类型</td>
            <td>房型图片</td>
            <td>操作</td>
        </tr>
        <tr v-for="item in list">
            <td>{{item.pname}}</td>
            <td>{{item.price}}</td>
            <td>{{item.cdate.substr(0,10)}}</td>
            <td>{{item.rname}}</td>
            <td><img :src="'https://localhost:7246'+item.rpicture" width="60" height="60"></td>
            <td><input type="button" value="修改" @click="wynskw(u=item.pid)"></td>
        </tr>
    </table>
    共<span style="color: red;">{{ count }}</span>条,每页<span style="color: red;">{{ lost.page }}</span>条,当前<span style="color: red;">{{ lost.index }}</span>/<span style="color: red;">{{ pcount }}</span>页
    
    <input type="button" value="首页" @click="setpage('a')">
    <input type="button" value="上一页" @click="setpage('b')">
    <input type="button" value="下一页" @click="setpage('c')">
    <input type="button" value="尾页" @click="setpage('d')">
  </template>
  
  <script setup lang="ts">
   import {onMounted, reactive, toRefs} from 'vue'
  import {useRouter,useRoute} from 'vue-router'
  import axios from 'axios'
import { pid } from 'process'
  const router=useRouter()
  const route=useRoute()

  let data:any=reactive({
    lost:{
        index:1,
        page:2
    },
    list:[],
    count:0,
    pcount:0
  })
  let {lost,list,count,pcount} =toRefs(data)

  onMounted(()=>{
    showlist()
  })

  const showlist=()=>{
    let obj={
        index:lost.value.index,
        page:lost.value.page
    }
    axios({
        url:'/api/Price/GetRoomprices',
        method:'get',
        params:obj
    })
    .then(res=>{
        list.value=res.data.data;
        count=res.data.coco;
        pcount=res.data.pro;
    })
  }

  const setpage=(val:any)=>{
    switch(val){
        case "a":
            lost.value.index=1;
            ;break;
        case "b":
            lost.value.index--;
            ;break;
        case "c":
            lost.value.index++;
            ;break;
        case "d":
            lost.value.index=pcount;
            ;break;
    }
    showlist()
  }

  const wynskw=(pid:any)=>{
    router.push({
        path:'/updprice',
        query:{
            pid:pid
        }
    })
  }

  const daochuwmws=()=>{
    location.href='https://localhost:7246'+'/api/Price/Exportexcal';
  }

  const luruwjms=()=>{
    router.push('addnum')
  }
  </script>
  
  <style scoped>
  
  </style>